package com.fireline.beauty.member;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import com.fireline.beauty.jdbc.SqliteJdbcImpl;
import com.zgw.fireline.base.controls.DataTable;
import com.zgw.fireline.base.controls.DataTableColumn;
import com.zgw.fireline.base.dataset.Dataset;
import com.zgw.fireline.base.frame.FunctionDialog;
import com.zgw.fireline.base.frame.IFunction;

/**
 * 会员交费统计视图
 * */
public class HyjftjView implements IFunction {
	private Text text;
	/**
	 * @wbp.nonvisual location=37,562
	 */
	private final Dataset dataset = new Dataset(
			"select a.*,b.hyxm,b.hykmc from hyjf a\r\n\t\tleft join hyxx b on a.hybh=b.hybh\r\n where \r\n (?='所有类型' or a.ztsm =? )\r\nand (a.hybh like '%'||ifnull(?,'')||'%' or b.hyxm like '%'||ifnull(?,'')||'%')\r\nand (?=0 or a.qk>0)",
			SqliteJdbcImpl.INSTANCE);
	private Combo combo;
	private Button button;
	private Shell shell;

	/**
	 * @wbp.parser.entryPoint
	 */
	@Override
	public Control createControl(Composite parent) {
		shell = parent.getShell();
		dataset.setKeyColumns(new String[] {});
		Composite content = new Composite(parent, SWT.NONE);
		content.setLayout(new GridLayout(1, false));

		ToolBar toolBar = new ToolBar(content, SWT.FLAT | SWT.RIGHT);
		toolBar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false,
				1, 1));

		ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem.setText("打印");

		ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
		toolItem.setText("导出");

		ToolItem toolItem_4 = new ToolItem(toolBar, SWT.SEPARATOR);

		ToolItem toolItem_2 = new ToolItem(toolBar, SWT.NONE);
		toolItem_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doHk();
			}
		});
		toolItem_2.setText("还款");

		ToolItem toolItem_5 = new ToolItem(toolBar, SWT.SEPARATOR);

		ToolItem tltmNewItem_1 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doOpenBz();
			}
		});
		tltmNewItem_1.setText("查看备注");

		ToolItem toolItem_3 = new ToolItem(toolBar, SWT.SEPARATOR);

		ToolItem toolItem_1 = new ToolItem(toolBar, SWT.NONE);
		toolItem_1.setText("退出");

		Composite composite = new Composite(content, SWT.NONE);
		composite.setLayout(new GridLayout(6, false));
		composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true,
				false, 1, 1));

		Label label = new Label(composite, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label.setText("交费类型：");

		combo = new Combo(composite, SWT.READ_ONLY);
		combo.setItems(new String[] { "所有类型", "储值卡交费", "套餐续费", "套餐退费" });
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
				1));
		combo.select(0);

		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		lblNewLabel.setText("会员信息：");

		text = new Text(composite, SWT.BORDER);
		GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
				1);
		gd_text.widthHint = 100;
		text.setLayoutData(gd_text);

		Button btnNewButton = new Button(composite, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doSearch();
			}
		});
		btnNewButton.setImage(null);
		btnNewButton.setText("查询");

		button = new Button(composite, SWT.CHECK);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doSearch();
			}
		});
		button.setText("只显示欠款记录");

		TabFolder tabFolder = new TabFolder(content, SWT.NONE);
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));

		TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
		tbtmNewItem.setText("交费详细信息");

		DataTable dataTable = new DataTable(tabFolder, SWT.BORDER
				| SWT.FULL_SELECTION, dataset);
		tbtmNewItem.setControl(dataTable);
		dataTable.setHeaderVisible(true);
		dataTable.setLinesVisible(true);

		DataTableColumn dataTableColumn = new DataTableColumn(dataTable,
				SWT.NONE, "hybh");
		dataTableColumn.setText("会员编号");
		dataTableColumn.setWidth(80);

		DataTableColumn dataTableColumn_1 = new DataTableColumn(dataTable,
				SWT.NONE, "hyxm");
		dataTableColumn_1.setText("会员姓名");
		dataTableColumn_1.setWidth(80);

		DataTableColumn dataTableColumn_2 = new DataTableColumn(dataTable,
				SWT.NONE, "hykmc");
		dataTableColumn_2.setText("会员卡名称");
		dataTableColumn_2.setWidth(80);

		DataTableColumn dataTableColumn_3 = new DataTableColumn(dataTable,
				SWT.NONE, "rq");
		dataTableColumn_3.setText("交费日期");
		dataTableColumn_3.setWidth(80);

		DataTableColumn dataTableColumn_4 = new DataTableColumn(dataTable,
				SWT.NONE, "ztsm");
		dataTableColumn_4.setText("交费类型");
		dataTableColumn_4.setWidth(80);

		DataTableColumn dataTableColumn_5 = new DataTableColumn(dataTable,
				SWT.NONE, "yfje");
		dataTableColumn_5.setText("应收金额");
		dataTableColumn_5.setWidth(80);

		DataTableColumn dataTableColumn_6 = new DataTableColumn(dataTable,
				SWT.NONE, "jfje");
		dataTableColumn_6.setText("实收金额");
		dataTableColumn_6.setWidth(80);

		DataTableColumn dataTableColumn_7 = new DataTableColumn(dataTable,
				SWT.NONE, "yhje");
		dataTableColumn_7.setText("赠送金额");
		dataTableColumn_7.setWidth(80);

		DataTableColumn dataTableColumn_13 = new DataTableColumn(dataTable,
				SWT.NONE, "yh");
		dataTableColumn_13.setText("优惠金额");
		dataTableColumn_13.setWidth(80);

		DataTableColumn dataTableColumn_8 = new DataTableColumn(dataTable,
				SWT.NONE, "qk");
		dataTableColumn_8.setText("欠款金额");
		dataTableColumn_8.setWidth(80);

		DataTableColumn dataTableColumn_9 = new DataTableColumn(dataTable,
				SWT.NONE, "xj");
		dataTableColumn_9.setText("现金");
		dataTableColumn_9.setWidth(80);

		DataTableColumn dataTableColumn_10 = new DataTableColumn(dataTable,
				SWT.NONE, "xyk");
		dataTableColumn_10.setText("信用卡");
		dataTableColumn_10.setWidth(80);

		DataTableColumn dataTableColumn_11 = new DataTableColumn(dataTable,
				SWT.NONE, "djq");
		dataTableColumn_11.setText("代金券");
		dataTableColumn_11.setWidth(80);

		DataTableColumn dataTableColumn_12 = new DataTableColumn(dataTable,
				SWT.NONE, "czk");
		dataTableColumn_12.setText("储值卡");
		dataTableColumn_12.setWidth(80);

		DataTableColumn dataTableColumn_14 = new DataTableColumn(dataTable,
				SWT.NONE, "bz");
		dataTableColumn_14.setText("备注");
		dataTableColumn_14.setWidth(80);
		TabItem tbtmNewItem_1 = new TabItem(tabFolder, SWT.NONE);
		tbtmNewItem_1.setText("交费排行图表");
		setParams();
		return content;
	}

	protected void doOpenBz() {
		if (dataset.getSelectedIndex() != -1) {
			MessageDialog.openInformation(shell, "备注信息",
					dataset.getString("bz"));
		}
	}

	protected void doHk() {
		if (dataset.getSelectedIndex() != -1) {
			HyjfhkDialog dlg = new HyjfhkDialog(shell, dataset.getString("id"));
			dlg.open();
		}
	}

	protected void doSearch() {
		setParams();
		dataset.update();
	}

	protected void setParams() {
		dataset.setParam(0, combo.getText());
		dataset.setParam(1, combo.getText());
		dataset.setParam(2, text.getText());
		dataset.setParam(3, text.getText());
		dataset.setParam(4, button.getSelection());
	}

	public static void main(String[] args) {
		HyjftjView view = new HyjftjView();
		FunctionDialog dlg = new FunctionDialog(new Shell(), view);
		dlg.open();
	}
}
